package com.itheima.advantagesup.controller;

import com.itheima.advantagesup.common.PageBean;
import com.itheima.advantagesup.common.R;
import com.itheima.advantagesup.dto.LinkUpdateDTO;
import com.itheima.advantagesup.dto.YddLinkByPageDTO;
import com.itheima.advantagesup.dto.YddLinkDTO;
import com.itheima.advantagesup.service.YddLinkService;
import com.itheima.advantagesup.vo.YddLinkVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


/**
 * @program: youdianda-2
 * @className: LinkController
 * @description: 链接管理
 * @author: xch
 * @createTime: 2023-07-29 14:22
 **/
@RestController
@RequestMapping("/ydd_link")
public class YddLinkController {

    @Autowired
    private YddLinkService yddLinkService;

    /**
     * Description 分页查询
     * @param yddLinkByPageDTO
     * @return com.itheima.advantagesup.common.R<com.itheima.advantagesup.common.PageBean<com.itheima.advantagesup.vo.YddLinkVO>>
     * Date 2023/7/29
     */
    @GetMapping("/list")
    public R<PageBean<YddLinkVO>> selectByPage(YddLinkByPageDTO yddLinkByPageDTO){
        return R.success(yddLinkService.selectByPage(yddLinkByPageDTO));
    }

    /**
     * Description 添加链接
     * @param yddLinkDTO
     * @return com.itheima.advantagesup.common.R<com.itheima.advantagesup.common.PageBean<com.itheima.advantagesup.vo.YddLinkVO>>
     * Date 2023/7/29
     */
    @PostMapping("/add")
    public R<?> addYddLink(@RequestBody YddLinkDTO yddLinkDTO){
        yddLinkService.addYddLink(yddLinkDTO);
        return R.success();
    }

    @GetMapping("/rowInfo")
    public R<?> rowInfo(String id){
        YddLinkVO yddLinkVO =yddLinkService.selectById(id);
        return R.success(yddLinkVO);
    }

    @PostMapping("/update")
    public R<?> update(@RequestBody LinkUpdateDTO linkUpdateDTO){
        yddLinkService.update(linkUpdateDTO);
        return R.success();
    }
}
